from django.shortcuts import render
from rest_framework.generics import ListAPIView, CreateAPIView, UpdateAPIView
from rest_framework.views import APIView
from areas.serializers import AreasSerialzer
from areas.models import Area
from rest_framework.response import Response
from rest_framework_extensions.cache.mixins import CacheResponseMixin
from areas.serializers import AddressSerializers

# Create your views here.


class AreasView(CacheResponseMixin,ListAPIView):
    serializer_class = AreasSerialzer
    queryset = Area.objects.filter(parent_id=None)


class AreasView2(CacheResponseMixin,ListAPIView):
    serializer_class = AreasSerialzer
    def get_queryset(self):
        pk = self.kwargs["pk"]
        return Area.objects.filter(parent_id=pk)


class AddressView(CreateAPIView, UpdateAPIView, ListAPIView):
    """
        保存地址
    """
    serializer_class = AddressSerializers
